% multiplier for price stickiness model
% Eric Sims
% July 11, 2013

var lam c rk z mu invs int infl wr f1 f2 khat v s L pr x1 x2 w y k eb eL A er einvs dy dc dI dL dw;

% MU of consumption; consumption; return on capital; utilization; multiplier on accumulation;
% investment; interest rate; inflation; reset wage; auxiliary variables f1 and f2;
% capital services; real marginal cost; price dispersion; gross output; labor;
% intermediate inputs; reset price; auxiliary variables x1 and x2; wage;
% output; capital; intertemporal preference shock; intratemporal preference shock;
% productivity; monetary shock; investment-specific shock

varexo ub uL uA ur uinvs ug ei1 ei2 ei3 ei4 ei5 ei6 ei7;

% shock to intertemporal preference; intratemporal preference; productivity; monetary policy; investment-specific

parameters beta b gamma1 gamma2 kappa delta pistar sigma chi eta xiw gammaw alpha phi F theta xip gammap alphapi alphay rhoi rhob rhoL rhoA rhor rhoinvs sub suL suA sur suinvs ints ys gup gi lams ls ks ws wrs ps gs x1s x2s f1s f2s xs mcs ss As vws css lamsf csf wrsf f1sf f2sf wsf lsf mcsf ssf xsf gsf psf x1sf x2sf ysf ksf invssf xipf xiwf Ff gaps alphax omegag rhog sug thetag sii;

% discount factor; habit formation; utilization cost; investment adjustment cost;
% depreciation; inflation target; elasticity of sub labor; inverse Frisch; labor disutility;
% calvo wages; indexation wages; capital share; intermediate share; fixed cost;
% elasticity of sub goods; calvo prices; indexation prices; TR inflation; 
% TR output; TR smoothing; AR shocks; SD shocks; ss interest rate; ss output 

load parameter_main_gov_peg;

set_param_value('beta',beta);
set_param_value('b',b);
set_param_value('gamma1',gamma1);
set_param_value('gamma2',gamma2);
set_param_value('kappa',kappa);
set_param_value('delta',delta);
set_param_value('pistar',pistar);
set_param_value('sigma',sigma);
set_param_value('chi',chi);
set_param_value('eta',eta);
set_param_value('xiw',xiw);
set_param_value('gammaw',gammaw);
set_param_value('alpha',alpha);
set_param_value('phi',phi);
set_param_value('F',F);
set_param_value('theta',theta);
set_param_value('xip',xip);
set_param_value('gammap',gammap);
set_param_value('alphapi',alphapi);
set_param_value('alphay',alphay);
set_param_value('rhoi',rhoi);
set_param_value('rhob',rhob);
set_param_value('rhoL',rhoL);
set_param_value('rhoA',rhoA);
set_param_value('rhor',rhor);
set_param_value('rhoinvs',rhoinvs);
set_param_value('sub',sub);
set_param_value('suL',suL);
set_param_value('suA',suA);
set_param_value('sur',sur);
set_param_value('suinvs',suinvs);
set_param_value('ints',ints);
set_param_value('ys',ys);
set_param_value('gup',gup);
set_param_value('gi',gi);
set_param_value('lams',lams);
set_param_value('ls',ls);
set_param_value('ks',ks);
set_param_value('ws',ws);
set_param_value('wrs',wrs);
set_param_value('ps',ps);
set_param_value('gs',gs);
set_param_value('x1s',x1s);
set_param_value('x2s',x2s);
set_param_value('f1s',f1s);
set_param_value('f2s',f2s);
set_param_value('xs',xs);
set_param_value('mcs',mcs);
set_param_value('ss',ss);
set_param_value('As',As);
set_param_value('vws',vws);
set_param_value('css',css);

set_param_value('ysf',ysf);
set_param_value('lamsf',lamsf);
set_param_value('lsf',lsf);
set_param_value('ksf',ksf);
set_param_value('wsf',wsf);
set_param_value('wrsf',wrsf);
set_param_value('psf',psf);
set_param_value('gsf',gsf);
set_param_value('x1sf',x1sf);
set_param_value('x2sf',x2sf);
set_param_value('f1sf',f1sf);
set_param_value('f2sf',f2sf);
set_param_value('xsf',xsf);
set_param_value('mcsf',mcsf);
set_param_value('ssf',ssf);
set_param_value('csf',csf);
set_param_value('invssf',invssf);
set_param_value('xiwf',xiwf);
set_param_value('xipf',xipf);
set_param_value('Ff',Ff);
set_param_value('gaps',gaps);
set_param_value('alphax',alphax);
set_param_value('omegag',omegag);
set_param_value('rhog',rhog);
set_param_value('sug',sug);
set_param_value('thetag',thetag);
set_param_value('sii',sii);

model;

% (1) marginal utility of consumption
exp(lam) = exp(eb)/(exp(c) - b*gup^(-1)*exp(c(-1))) - beta*b*exp(eb(+1))/(gup*exp(c(+1)) - b*exp(c));

% (2) FOC for utilization
%exp(rk) = (gamma1 + gamma2*(exp(z) - 1));
%exp(rk) = delta + gamma1 + gamma2*(exp(z) - 1);
exp(lam)*exp(rk) = exp(mu)*(gamma1 + gamma2*(exp(z) - 1));

% (3) investment FOC
exp(lam) = exp(mu)*exp(einvs)*(1 - (kappa/2)*(exp(invs)/exp(invs(-1))*gup - gup)^2 - kappa*(exp(invs)/exp(invs(-1))*gup - gup)*(exp(invs)/exp(invs(-1)))*gup) + beta*gup^(-1)*exp(mu(+1))*exp(einvs(+1))*kappa*(exp(invs(+1))/exp(invs)*gup - gup)*(gup*exp(invs(+1))/exp(invs))^2;

% (4) capital FOC
%gi*gup*exp(mu) = beta*exp(lam(+1))*(exp(rk(+1))*exp(z(+1)) - (gamma1*(exp(z(+1)) - 1) + (gamma2/2)*(exp(z(+1)) - 1)^2)) + beta*(1-delta)*exp(mu(+1));
%gi*gup*exp(mu) = beta*exp(lam(+1))*(exp(rk(+1))*exp(z(+1)) - (gamma1*(exp(z(+1)) - 1) + (gamma2/2)*(exp(z(+1)) - 1)^2)) + beta*(1-delta)*exp(mu(+1));
gi*gup*exp(mu) = beta*exp(lam(+1))*(exp(rk(+1))*exp(z(+1))) + beta*(1-(delta + gamma1*(exp(z(+1)) - 1) + (gamma2/2)*(exp(z(+1)) - 1)^2))*exp(mu(+1));

% (5) bonds FOC
exp(lam) = beta*gup^(-1)*(1+int)*exp(infl(+1))^(-1)*exp(lam(+1));

% (6) Reset wage
exp(wr) = (sigma/(sigma - 1))*exp(f1)/exp(f2);

% (7) Auxiliary f1
exp(f1) = exp(eb)*exp(eL)*eta*(exp(wr)/exp(w))^(-sigma*(1+chi))*exp(L)^(1+chi) + beta*xiw*((exp(wr)/exp(wr(+1)))*(exp(infl)^(gammaw)/exp(infl(+1))))^(-sigma*(1+chi))*gup^(sigma*(1+chi))*exp(f1(+1));

% (8) Auxiliary f2
exp(f2) = exp(lam)*(exp(wr)/exp(w))^(-sigma)*exp(L) + beta*xiw*(exp(wr)/exp(wr(+1)))^(-sigma)*(exp(infl)^(gammaw)/exp(infl(+1)))^(1-sigma)*gup^(sigma-1)*exp(f2(+1));

% (9) Capital services demand
%exp(khat) = gi*gup*alpha*(1-phi)*(exp(v)/exp(rk))*(exp(s)*exp(x) + F);
exp(rk) = alpha*(1-phi)*exp(v)*exp(A)*exp(khat)^(alpha - 1)*exp(L)^(1-alpha);

% (10) Labor demand
%exp(L) = (1-alpha)*(1-phi)*(exp(v)/exp(w))*(exp(s)*exp(x) + F);
exp(w) = (1-alpha)*(1-phi)*exp(v)*exp(A)*exp(khat)^(alpha)*exp(L)^(-alpha);

% (11) Intermediates demand
%exp(Gamma) = phi*exp(v)*(exp(s)*exp(x) + F);
%1 = phi*exp(v)*exp(A)*exp(Gamma)^(phi-1)*exp(khat)^(alpha*(1-phi))*exp(L)^((1-alpha)*(1-phi));

% (12) Reset price
exp(pr) = (theta/(theta-1))*(exp(x1)/exp(x2));

% (13) Auxiliary x1
exp(x1) = exp(lam)*exp(v)*exp(y) + xip*beta*(exp(infl)^(gammap)/exp(infl(+1)))^(-theta)*exp(x1(+1));

% (14) Auxiliary x2
exp(x2) = exp(lam)*exp(y) + xip*beta*(exp(infl)^(gammap)/exp(infl(+1)))^(1-theta)*exp(x2(+1));

% (15) Price evolution
1 = xip*(exp(infl(-1))^(gammap)/exp(infl))^(1-theta) + (1-xip)*exp(pr)^(1-theta);

% (16) Wage evolution
exp(w)^(1-sigma) = xiw*gup^(sigma-1)*(exp(w(-1))*(exp(infl(-1))^(gammaw)/exp(infl)))^(1-sigma) + (1-xiw)*exp(wr)^(1-sigma);

% (17) Aggregate output
%exp(y) = exp(x) - exp(Gamma);

% (18) Aggregate production
exp(s)*exp(y) = exp(A)*(exp(khat)^(alpha)*exp(L)^(1-alpha))*gup^(-alpha)*gi^(-alpha) - F;

% (19) Accounting
%exp(y) = exp(c) + exp(invs) + gi^(-1)*gup^(-1)*(gamma1*(exp(z) - 1) + (gamma2/2)*(exp(z) - 1)^2)*(exp(k(-1))) + exp(gov);
exp(y) = exp(c) + exp(invs);


% (20) Capital accumulation
%exp(k) = exp(einvs)*(1 - (kappa/2)*(exp(invs)/exp(invs(-1))*gup - gup)^2)*exp(invs) + (1-delta)*gup^(-1)*gi^(-1)*exp(k(-1));
exp(k) = exp(einvs)*(1 - (kappa/2)*(exp(invs)/exp(invs(-1))*gup - gup)^2)*exp(invs) + (1-(delta + gamma1*(exp(z) - 1) + (gamma2/2)*(exp(z) - 1)^2))*gup^(-1)*gi^(-1)*exp(k(-1));


% (21) Taylor rule
%((1+int)/(1+ints)) = ((exp(infl)/pistar)^(alphapi)*(exp(y)/exp(y(-1)))^(alphay))^(1-rhoi)*((1+int(-1))/(1+ints))^(rhoi)*exp(er);
((1+int)/(1+ints)) = ((exp(infl)/pistar)^(alphapi)*(exp(dy)/gup)^(alphay))^(1-rhoi)*((1+int(-1))/(1+ints))^(rhoi)*exp(er)*exp(ei1(-1))*exp(ei2(-2))*exp(ei3(-3))*exp(ei4(-4))*exp(ei5(-5))*exp(ei6(-6))*exp(ei7(-7));

%((1+int)/(1+ints)) = ((exp(infl)/pistar)^(alphapi)*(exp(dy)/gup)^(alphay)*(gap/gaps)^(alphax))^(1)*((1+int(-1))/(1+ints))^(rhoi)*exp(er);
%int = (1-rhoi)*ints + rhoi*int(-1) + alphapi*(infl-log(pistar)) + alphay*(dy - log(gup)) + alphax*(log(gap)-log(gaps)) + er;
%dy = log(gup);
%infl = log(pistar);
%infl = log(pistar);
%gap = gaps;

% (22) Capital services
exp(khat) = exp(z)*exp(k(-1));

% (23) Price dispersion
exp(s) = (1-xip)*exp(pr)^(-theta) + xip*(exp(infl(-1))^(gammap)/exp(infl))^(-theta)*exp(s(-1));

% (24) Intertemporal preference shock
exp(eb) = exp(eb(-1))^(rhob)*exp(ub);
%eb = (1-rhob) + rhob*eb(-1) + ub;

% (25) Intratemporal preferenec shock
exp(eL) = exp(eL(-1))^(rhoL)*exp(uL);

% (26) Productivity shock
exp(A) = exp(A(-1))^(rhoA)*As^(1-rhoA)*exp(uA);

% (27) Monetary policy shock
exp(er) = exp(er(-1))^(rhor)*exp(ur);

% (28) Investment-specific shock
exp(einvs) = exp(einvs(-1))^(rhoinvs)*exp(uinvs);

dy = y - y(-1) + log(gup);

dc = c - c(-1) + log(gup);

dI = invs - invs(-1) + log(gup);

dL = L - L(-1);

dw = w - w(-1) + log(gup);


%%%%%%%%%%%%%%%%%%%% flexible price block of model




end;

initval;
A = log(As);
einvs = 0;
er = 0;
eL = 0;
eb = 0;
z = 0;
y = log(ys);
int = ints;
rk = log(gamma1);
lam = log(lams);
L = log(ls);
w = log(ws);
wr = log(wrs);
pr = log(ps);
k = log(ks);
x1 = log(x1s);
x2 = log(x2s);
f1 = log(f1s);
f2 = log(f2s);
mu = log(lams);
infl = log(pistar);
c = log(css);
invs = log((1-(1-delta)*gup^(-1)*gi^(-1))*ks);
khat = log(ks);
v = log(mcs);
s = log(ss);
dy = log(gup);
dc = log(gup);
dI = log(gup);
dL = 0;
dw = log(gup);
y = log(ysf);
end;

steady;

shocks;
var ub = sub^2;
var uL = suL^2;
var uA = suA^2;
var ur = sur^2;
var uinvs = suinvs^2;
var ug = sug^2;
var ei1 = sii^2;
var ei2 = sii^2;
var ei3 = sii^2;
var ei4 = sii^2;
var ei5 = sii^2;
var ei6 = sii^2;
var ei7 = sii^2;
end;

stoch_simul(order=1,irf=0,pruning,nograph,ar=0,nomoments,nocorr,noprint);